﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
using System.Collections.Generic;//请先添加引用
namespace EnterpriseFund.DAL
{
    /// <summary>
    /// 数据访问类PrvUser。
    /// </summary>
    public class PrvUser
    {
        public PrvUser()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string FLogID, string FEntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from t_PrvUser");
            strSql.Append(" where FLogID=@FLogID and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,50),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = FLogID;
            parameters[1].Value = FEntityNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Model.PrvUser model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_PrvUser(");
            strSql.Append("FLogID,FEntityNo,FUserName,Fpassword,FLastLoginTime,FLastLoginIPAddr,FLoginCnt,FProhibitLogin,FForeverAvailable,FAvailableDate,FEmplNo)");
            strSql.Append(" values (");
            strSql.Append("@FLogID,@FEntityNo,@FUserName,@Fpassword,@FLastLoginTime,@FLastLoginIPAddr,@FLoginCnt,@FProhibitLogin,@FForeverAvailable,@FAvailableDate,@FEmplNo)");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUserName", SqlDbType.NVarChar,30),
					new SqlParameter("@Fpassword", SqlDbType.NVarChar,255),
					new SqlParameter("@FLastLoginTime", SqlDbType.DateTime),
					new SqlParameter("@FLastLoginIPAddr", SqlDbType.NVarChar,15),
					new SqlParameter("@FLoginCnt", SqlDbType.Int,4),
					new SqlParameter("@FProhibitLogin", SqlDbType.Int,4),
					new SqlParameter("@FForeverAvailable", SqlDbType.Int,4),
					new SqlParameter("@FAvailableDate", SqlDbType.DateTime),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = model.FLogID;
            parameters[1].Value = model.FEntityNo;
            parameters[2].Value = model.FUserName;
            parameters[3].Value = model.Fpassword;
            parameters[4].Value = model.FLastLoginTime;
            parameters[5].Value = model.FLastLoginIPAddr;
            parameters[6].Value = model.FLoginCnt;
            parameters[7].Value = model.FProhibitLogin;
            parameters[8].Value = model.FForeverAvailable;
            parameters[9].Value = model.FAvailableDate;
            parameters[10].Value = model.FEmplNo;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Model.PrvUser model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_PrvUser set ");
            strSql.Append("FUserName=@FUserName,");
            strSql.Append("Fpassword=@Fpassword,");
            strSql.Append("FLastLoginTime=@FLastLoginTime,");
            strSql.Append("FLastLoginIPAddr=@FLastLoginIPAddr,");
            strSql.Append("FLoginCnt=@FLoginCnt,");
            strSql.Append("FProhibitLogin=@FProhibitLogin,");
            strSql.Append("FForeverAvailable=@FForeverAvailable,");
            strSql.Append("FAvailableDate=@FAvailableDate,");
            strSql.Append("FEmplNo=@FEmplNo");
            strSql.Append(" where FLogID=@FLogID and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUserName", SqlDbType.NVarChar,30),
					new SqlParameter("@Fpassword", SqlDbType.NVarChar,255),
					new SqlParameter("@FLastLoginTime", SqlDbType.DateTime),
					new SqlParameter("@FLastLoginIPAddr", SqlDbType.NVarChar,15),
					new SqlParameter("@FLoginCnt", SqlDbType.Int,4),
					new SqlParameter("@FProhibitLogin", SqlDbType.Int,4),
					new SqlParameter("@FForeverAvailable", SqlDbType.Int,4),
					new SqlParameter("@FAvailableDate", SqlDbType.DateTime),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = model.FLogID;
            parameters[1].Value = model.FEntityNo;
            parameters[2].Value = model.FUserName;
            parameters[3].Value = model.Fpassword;
            parameters[4].Value = model.FLastLoginTime;
            parameters[5].Value = model.FLastLoginIPAddr;
            parameters[6].Value = model.FLoginCnt;
            parameters[7].Value = model.FProhibitLogin;
            parameters[8].Value = model.FForeverAvailable;
            parameters[9].Value = model.FAvailableDate;
            parameters[10].Value = model.FEmplNo;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string FLogID, string FEntityNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_PrvUser ");
            strSql.Append(" where FLogID=@FLogID and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,50),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = FLogID;
            parameters[1].Value = FEntityNo;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);


            //删除相应的登录用户的文明台帐的权限表
            strSql = new StringBuilder();
            strSql.Append("delete from t_accManagerDirAuth ");
            strSql.Append(" where FLogID=@FLogID");

            SqlParameter[] parameters1 = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,50)};
            parameters1[0].Value = FLogID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters1);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.PrvUser GetModel(string FLogID, string FEntityNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FLogID,FEntityNo,FUserName,Fpassword,FLastLoginTime,FLastLoginIPAddr,FLoginCnt,FProhibitLogin,FForeverAvailable,FAvailableDate,FEmplNo from t_PrvUser ");
            strSql.Append(" where FLogID=@FLogID and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,50),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = FLogID;
            parameters[1].Value = FEntityNo;

            Model.PrvUser model = new Model.PrvUser();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.FLogID = ds.Tables[0].Rows[0]["FLogID"].ToString();
                model.FEntityNo = ds.Tables[0].Rows[0]["FEntityNo"].ToString();
                model.FUserName = ds.Tables[0].Rows[0]["FUserName"].ToString();
                model.Fpassword = ds.Tables[0].Rows[0]["Fpassword"].ToString();
                if (ds.Tables[0].Rows[0]["FLastLoginTime"].ToString() != "")
                {
                    model.FLastLoginTime = DateTime.Parse(ds.Tables[0].Rows[0]["FLastLoginTime"].ToString());
                }
                model.FLastLoginIPAddr = ds.Tables[0].Rows[0]["FLastLoginIPAddr"].ToString();
                if (ds.Tables[0].Rows[0]["FLoginCnt"].ToString() != "")
                {
                    model.FLoginCnt = int.Parse(ds.Tables[0].Rows[0]["FLoginCnt"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FProhibitLogin"].ToString() != "")
                {
                    model.FProhibitLogin = int.Parse(ds.Tables[0].Rows[0]["FProhibitLogin"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FForeverAvailable"].ToString() != "")
                {
                    model.FForeverAvailable = int.Parse(ds.Tables[0].Rows[0]["FForeverAvailable"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FAvailableDate"].ToString() != "")
                {
                    model.FAvailableDate = DateTime.Parse(ds.Tables[0].Rows[0]["FAvailableDate"].ToString());
                }
                model.FEmplNo = ds.Tables[0].Rows[0]["FEmplNo"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FLogID,FEntityNo,FUserName,Fpassword,FLastLoginTime,FLastLoginIPAddr,FLoginCnt,FProhibitLogin,FForeverAvailable,FAvailableDate,FEmplNo,FSSOUid ");
            strSql.Append(" FROM t_PrvUser ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FLogID,FEntityNo,FUserName,Fpassword,FLastLoginTime,FLastLoginIPAddr,FLoginCnt,FProhibitLogin,FForeverAvailable,FAvailableDate,FEmplNo ");
            strSql.Append(" FROM t_PrvUser ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_PrvUser";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法

        #region 自己增加的方法

        /// <summary>
        /// 根据用户登陆号、密码、单位编码判断用户是否存在
        /// </summary>
        /// <param name="logid"></param>
        /// <param name="password"></param>
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public bool ExistsByNameAndPassword(string logid, string password, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from t_PrvUser");
            strSql.Append(" where FLogID=@FLogID and Fpassword=@Fpassword and FEntityNo=@FEntityNo");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.VarChar,50),
                    new SqlParameter("@Fpassword", SqlDbType.VarChar,50),
                    new SqlParameter("@FEntityNo", SqlDbType.VarChar,50)};
            parameters[0].Value = logid;
            parameters[1].Value = password;
            parameters[2].Value = entityNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        public string GetThemePrvUser(string strEntityNo, string strLogId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT TOP 1 FDevTheme FROM t_PrvUser where FEntityNo=@FEntityNo and FLogID=@FLogID");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.VarChar,30),			
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,12)};
            parameters[0].Value = strLogId;
            parameters[1].Value = strEntityNo;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return "";
            }
            else
            {
                return obj.ToString();
            }

        }
        public bool UpdateThemePrvUser(string strEntityNo, string strLogId, string Theme)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("UPDATE  t_PrvUser SET FDevTheme =@Theme  where FEntityNo=@FEntityNo and FLogID=@FLogID");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.VarChar,30),			
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,12),
            	new SqlParameter("@Theme", SqlDbType.NVarChar,32)};
            parameters[0].Value = strLogId;
            parameters[1].Value = strEntityNo;
            parameters[2].Value = Theme;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 获取正级编号
        /// </summary>
        /// <param name="deptNo"></param>
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public string GetPropEmpNo(string deptNo, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT FEmplNo FROM dbo.v_HREmpl WHERE FPositionProp=1  AND FDeptNo='" + deptNo + "' AND FEntityNo='" + entityNo + "' ");
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj != null)
            {
                return obj.ToString();
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获取正级手机号
        /// </summary>
        /// <param name="deptNo"></param>   
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public string GetMobile(string emplNo, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT FMobile FROM dbo.v_HREmpl WHERE FEmplNo='" + emplNo + "' AND FEntityNo='" + entityNo + "' ");
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj != null)
            {
                return obj.ToString();
            }
            else
            {
                return null;
            }
        }



        /// <summary>
        /// 得到一个对象实体,根据用户登陆号、密码、单位编码
        /// </summary>
        /// <param name="logid"></param>
        /// <param name="password"></param>
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public Model.PrvUser GetModelByNameAndPassword(string logid, string password, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FLogID,FUserName,Fpassword,FLastLoginTime,FLastLoginIPAddr,FLoginCnt,FProhibitLogin,FForeverAvailable,FAvailableDate,FEntityNo, FEmplNo from t_PrvUser ");
            strSql.Append(" where FLogID=@FLogID and FEntityNo=@FEntityNo and Fpassword=@Fpassword");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.VarChar,50),
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,50),
                    new SqlParameter("@Fpassword", SqlDbType.VarChar,50)};

            parameters[0].Value = logid;
            parameters[1].Value = entityNo;
            parameters[2].Value = password;

            Model.PrvUser model = new Model.PrvUser();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.FLogID = ds.Tables[0].Rows[0]["FLogID"].ToString();
                model.FUserName = ds.Tables[0].Rows[0]["FUserName"].ToString();
                model.Fpassword = ds.Tables[0].Rows[0]["Fpassword"].ToString();
                if (ds.Tables[0].Rows[0]["FLastLoginTime"].ToString() != "")
                {
                    model.FLastLoginTime = DateTime.Parse(ds.Tables[0].Rows[0]["FLastLoginTime"].ToString());
                }
                model.FLastLoginIPAddr = ds.Tables[0].Rows[0]["FLastLoginIPAddr"].ToString();
                if (ds.Tables[0].Rows[0]["FLoginCnt"].ToString() != "")
                {
                    model.FLoginCnt = int.Parse(ds.Tables[0].Rows[0]["FLoginCnt"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FProhibitLogin"].ToString() != "")
                {
                    model.FProhibitLogin = int.Parse(ds.Tables[0].Rows[0]["FProhibitLogin"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FForeverAvailable"].ToString() != "")
                {
                    model.FForeverAvailable = int.Parse(ds.Tables[0].Rows[0]["FForeverAvailable"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FAvailableDate"].ToString() != "")
                {
                    model.FAvailableDate = DateTime.Parse(ds.Tables[0].Rows[0]["FAvailableDate"].ToString());
                }
                model.FEntityNo = ds.Tables[0].Rows[0]["FEntityNo"].ToString();
                if (ds.Tables[0].Rows[0]["FEmplNo"].ToString() != "")
                {
                    model.FEmplNo = ds.Tables[0].Rows[0]["FEmplNo"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 取出相应的用户
        /// </summary>
        /// <param name="GroupNo">组名</param>
        /// <param name="LeftOrRight">输入left或right,确定是左边listbox还是右边listbox</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public DataSet GetListByGroup(string GroupNo, string LeftOrRight, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FLogID,FUserName");
            strSql.Append(" FROM t_PrvUser ");
            if (LeftOrRight == "left")
            {
                strSql.Append(" where FLogID not in (");
                strSql.Append(" select FLogID from t_PrvUserGroup where FGroupNo=@FGroupNo and FEntityNo=@FEntityNo) and FEntityNo=@FEntityNo");
            }
            else if (LeftOrRight == "right")
            {
                strSql.Append(" where FLogID in (");
                strSql.Append(" select FLogID from t_PrvUserGroup where FGroupNo=@FGroupNo and FEntityNo=@FEntityNo) and FEntityNo=@FEntityNo");
            }

            strSql.Append(" order by FUserName asc");

            SqlParameter[] parameters = {
					new SqlParameter("@FGroupNo", SqlDbType.VarChar,50),
                    new SqlParameter("@FEntityNo", SqlDbType.VarChar,50)};
            parameters[0].Value = GroupNo;
            parameters[1].Value = entityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }

        /// <summary>
        /// 获取数据和部门编号 FLogID,FUserName,FDeptNo
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <returns>用户信息列表</returns>
        public DataSet GetListDept(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select a.FLogID,a.FUserName,a.FDeptNo from v_PrvUser a,v_HREmpl b
                            where a.FEmplNo=b.FEmplNo AND a.FDeptNo=b.FDeptNo and a.FEntityNo=b.FEntityNo and b.FIsMainPosition='Y' and  FEmpStatus in('02','01') ");
            strSql.Append(" and a.FEntityNo=@FEntityNo ");
            strSql.Append(" ORDER BY a.FSeq");
            SqlParameter[] parameters = {
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar, 15) };
            parameters[0].Value = entityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获得数据列表,根据公司编号
        /// </summary>
        public DataSet GetListByEntityNo(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FLogID,FUserName,Fpassword,FLastLoginTime,FLastLoginIPAddr,FLoginCnt,FProhibitLogin,FForeverAvailable,FAvailableDate,FEntityNo ");
            strSql.Append(" FROM t_PrvUser ");
            strSql.Append(" where FEntityNo=@FEntityNo");
            strSql.Append(" order by FUserName asc");
            SqlParameter[] parameters = {
                   new SqlParameter("@FEntityNo",SqlDbType.VarChar,50)};
            parameters[0].Value = entityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 从视图中获取数据列表，那部门和人员排序,部分字段 FLogID FUserName
        /// </summary>
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public DataSet GetListByEntityNoOnView(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT dbo.t_PrvUser.FLogID, dbo.t_PrvUser.FUserName FROM dbo.t_PrvUser LEFT OUTER JOIN dbo.v_HREmpl ON dbo.t_PrvUser.FEntityNo = dbo.v_HREmpl.FEntityNo AND  dbo.t_PrvUser.FEmplNo = dbo.v_HREmpl.FEmplNo ");
            strSql.Append(" where dbo.t_PrvUser.FEntityNo=@FEntityNo");
            strSql.Append(" ORDER BY dbo.v_HREmpl.FDeptSeq, dbo.v_HREmpl.FSeq ");
            SqlParameter[] parameters = {
                   new SqlParameter("@FEntityNo",SqlDbType.VarChar,50)};
            parameters[0].Value = entityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 根据公司编号和部门编号获取
        /// </summary>
        /// <param name="FEntityNo"></param>
        /// <param name="FEmplNo"></param>
        /// <returns></returns>
        public DataSet GetModelListByEmplNo(string FEntityNo, string FDeptNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FLogID,FUserName,Fpassword,FLastLoginTime,FLastLoginIPAddr,FLoginCnt,FProhibitLogin,FForeverAvailable,FAvailableDate,FEntityNo,FEmplNo ");
            strSql.Append(" FROM v_PrvUser ");
            strSql.Append(" where FEntityNo=@FEntityNo and FDeptNo=@FDeptNo order by FSeq asc");
            SqlParameter[] parameters = {
                   new SqlParameter("@FEntityNo",SqlDbType.VarChar,50),
                   new SqlParameter("@FDeptNo",SqlDbType.NVarChar,12)};
            parameters[0].Value = FEntityNo;
            parameters[1].Value = FDeptNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 根据公司编号和部门编号获取
        /// </summary>
        /// <param name="FEntityNo"></param>
        /// <param name="FEmplNo"></param>
        /// <returns></returns>
        public DataSet GetModelListInHREmpl(string FEntityNo, string FDeptNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEmpName,FEmplNo ");
            strSql.Append(" FROM v_HREmpl ");
            strSql.Append(" where FEntityNo=@FEntityNo and FDeptNo=@FDeptNo and FIsMainPosition='Y' and FEmpStatus in('02','01') order by FSeq asc");
            SqlParameter[] parameters = {
                   new SqlParameter("@FEntityNo",SqlDbType.VarChar,50),
                   new SqlParameter("@FDeptNo",SqlDbType.NVarChar,12)};
            parameters[0].Value = FEntityNo;
            parameters[1].Value = FDeptNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 根据用户登录号和公司编号获取一个员工ID
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="strLogId"></param>
        /// <returns></returns>
        public string getEmplNo(string strEntityNo, string strLogId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 FEmplNo FROM t_PrvUser where FEntityNo=@FEntityNo and FLogID=@FLogID");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.VarChar,30),			
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,12)};
            parameters[0].Value = strLogId;
            parameters[1].Value = strEntityNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                if (sdr.Read())
                {
                    return sdr[0].ToString();
                }
            }

            return "";
        }


        /// <summary>
        /// 根据用户登录号和公司编号获取一个员工ID和员工名称
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="strLogId"></param>
        /// <returns></returns>
        public List<string> getEmplNoAndUserName(string strEntityNo, string strLogId)
        {
            List<string> liststr = new List<string>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 FEmplNo,FEmpName FROM v_PrvUser where FEntityNo=@FEntityNo and FLogID=@FLogID");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.VarChar,30),			
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,12)};
            parameters[0].Value = strLogId;
            parameters[1].Value = strEntityNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                if (sdr.Read())
                {
                    liststr.Add(sdr[0].ToString());
                    liststr.Add(sdr[1].ToString());
                }
            }

            return liststr;
        }

        /// <summary>
        /// 获取员工ID和部门ID
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="strLogId"></param>
        /// <returns></returns>
        public List<string> getEmplNoAndDeptNo(string strEntityNo, string strLogId)
        {
            List<string> liststr = new List<string>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 FEmplNo,FDeptNo FROM v_PrvUser where FEntityNo=@FEntityNo and FLogID=@FLogID");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.VarChar,30),			
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,12)};
            parameters[0].Value = strLogId;
            parameters[1].Value = strEntityNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                if (sdr.Read())
                {
                    liststr.Add(sdr[0].ToString());
                    liststr.Add(sdr[1].ToString());
                }
            }

            return liststr;
        }


               /// <summary>
        /// 获取员工ID和部门ID
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="strLogId"></param>
        /// <returns></returns>
        public List<string> getEmpl(string strEntityNo, string strLogId)
        {
            List<string> liststr = new List<string>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT FEmplNo,FDeptNo  FROM dbo.v_HREmpl WHERE FIsMainPosition='Y'  and  FEntityNo=@FEntityNo and FEmplNo=@FLogID");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.VarChar,30),			
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,12)};
            parameters[0].Value = strLogId;
            parameters[1].Value = strEntityNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                if (sdr.Read())
                {
                    liststr.Add(sdr[0].ToString());
                    liststr.Add(sdr[1].ToString());
                }
            }

            return liststr;
        }



        /// <summary>
        /// 根据公司编号和登录ID获取员工编号和部门编号
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="strLogId"></param>
        /// <returns></returns>
        public List<string> getEmpNoAndDeptNo(string strEntityNo, string strLogId)
        {
            List<string> listStr = new List<string>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 FEmplNo,FDeptNo FROM v_PrvUser where FEntityNo=@FEntityNo and FLogID=@FLogID");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.VarChar,30),			
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,12)};
            parameters[0].Value = strLogId;
            parameters[1].Value = strEntityNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                if (sdr.Read())
                {
                    listStr.Add(sdr[0].ToString());
                    listStr.Add(sdr[1].ToString());
                }
            }

            return listStr;
        }

        /// <summary>
        /// 取消门户统一登陆绑定
        /// </summary>
        /// <param name="FLogID"></param>
        /// <param name="FEntityNo"></param>
        public void cancelUserUnifyLogin(string FLogID, string FEntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_PrvUser set ");
            strSql.Append("FSSOUid='' ");
            strSql.Append(" where FLogID=@FLogID and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = FLogID;
            parameters[1].Value = FEntityNo;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        #endregion


    }
}

